#!/usr/bin/env python
#-*- coding: utf-8 -*-
#
# Copyright 2013 Antoine Drouin (poinix@gmail.com)
#
# This file is part of PAT.
#
#    PAT is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    PAT is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with PAT.  If not, see <http://www.gnu.org/licenses/>.
#

"""
Demonstrates how to get equilibrium for the rotorcraft synthesis dynamic model 
"""

import numpy as np
import scipy
import scipy.integrate
import matplotlib.pyplot as plt

import pat.vehicles.rotorcraft.dynamic_model_synth as dm
import pat.utils as pu


my_dm = dm.DynamicModel()
print "Param:\n", my_dm.P

args = {'om':pu.rps_of_rpm(1700.), 'vel':0.}
Xe, Ue = my_dm.trim(args, debug=True)
print "args", args
print "Xe\n", Xe
print "Ue ", Ue
time = np.arange(0., 10., 0.01)
X = scipy.integrate.odeint(dm.dyn, Xe, time, args=(Ue, my_dm.P, ))
my_dm.plot_trajectory(time, X, Ue*np.ones((len(time), dm.iv_size)))

#args = {'om':pu.rps_of_rpm(1900.), 'vel':0.}
#Xe, Ue = my_dm.trim(args=args)
#print "args", args
#print "Xe\n", Xe
#print "Ue ", Ue

args = {'om':pu.rps_of_rpm(1700.), 'vel':2.}
Xe, Ue = my_dm.trim(args, debug=True)
print "args", args
print "Xe\n", Xe
print "Ue ", Ue
my_dm.reset(Xe)
X = scipy.integrate.odeint(dm.dyn, Xe, time, args=(Ue, my_dm.P, ))
my_dm.plot_trajectory(time, X, Ue*np.ones((len(time), dm.iv_size)))
plt.show()
